﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Xml.Linq;

namespace RFW.Silverlight.Weather
{
	public class Wind
	{
		public string Description { get; set; }
		public string DirectionDescription { get; set; }
		public int Direction { get; set; }
		public double Speed { get; set; }
		public double GustSpeed { get; set; }

		public override string ToString()
		{
			return this.Description;
		}

		internal void Process(XDocument doc)
		{
			var data = from o in doc.Descendants("current_observation")
						   select new Wind
						   {
							   Description = o.Element("wind_string").Value,
							   DirectionDescription = o.Element("wind_dir").Value,
							   Direction = Convert.ToInt32(o.Element("wind_degrees").Value),
							   Speed = Convert.ToDouble(o.Element("wind_mph").Value),
							   GustSpeed = Convert.ToDouble(o.Element("wind_gust_mph").Value)
						   };

			foreach (Wind o in data)
			{
				this.Description = o.Description;
				this.DirectionDescription = o.DirectionDescription;
				this.Direction = o.Direction;
				this.Speed = o.Speed;
				this.GustSpeed = o.GustSpeed;
			}
		}
	}
}
